package com.ujs.controller;

import com.ujs.pojo.Log;
import com.ujs.pojo.Order;
import com.ujs.pojo.Role;
import com.ujs.service.LogService;
import com.ujs.service.RoleService;
import com.ujs.utils.PageUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;

import java.util.List;

@Controller
@RequestMapping("/log")
public class LogController {
    @Autowired
    private LogService logService;

//    @GetMapping("/findAll")
    public String findAll(Model model) {
        List<Log> syslogs = logService.findAll();
        model.addAttribute("syslogs", syslogs);
        return "syslog-list";
    }
    @RequestMapping("/findAll")
    public String findAllByPage(Model model,@RequestParam(name = "page", required = true, defaultValue = "1") Integer page,
                                @RequestParam(name = "pageSize", required = true, defaultValue = "4") Integer pageSize){
        List<Log> list = logService.findAll();
        PageUtil<Log> pageInfo = new PageUtil<>(page, pageSize, list);
        List<Log> syslogs = pageInfo.getList();
        model.addAttribute("pageInfo",pageInfo);
        model.addAttribute("syslogs",syslogs);
        return "syslog-list";
    }

}
